//
//  AppDelegate.swift
//  CSWeibo
//
//  Created by 白长松 on 16/6/29.
//  Copyright © 2016年 白长松. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
        window = UIWindow()
        window?.backgroundColor = UIColor.white()
        window?.rootViewController = WBMainViewController()
        window?.makeKeyAndVisible()
        
        loadAppInfo()
        
        return true
    }
}

extension AppDelegate {
    
    func loadAppInfo() {
        
        //模拟网络异步加载json文件保存到本地
        DispatchQueue.global().async { 
            let url = Bundle.main().urlForResource("Main.json", withExtension: nil)
            let data = NSData(contentsOf: url!)
            
            let docDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
            
            let jsonPath = (docDir as NSString).appendingPathComponent("Main.json")
            
            data?.write(toFile: jsonPath, atomically: true)
            
        }
    }
}
